package com.gg.zjj.controller;

import com.gg.common.pojo.MManufacture;
import com.gg.common.pojo.MProcedureIng;
import com.gg.common.pojo.MProcedureModuleIng;
import com.gg.zjj.service.MManufactureService;
import com.gg.zjj.util.Result;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author koco
 * 2022/10/21
 * 16:39
 */
@Controller
@RequestMapping("/zjj/")
public class productionRegistrationController {

    @Resource
    private MManufactureService manufactureService;



    @RequestMapping("queryProductionDispatchOrdersToBeRegistered.action")
    @ResponseBody
    private Result<List<MManufacture>> queryProductionDispatchOrdersToBeRegistered(){
        return Result.success(manufactureService.queryProductionDispatchOrdersToBeRegistered());
    }

    @RequestMapping("submitMaterialProduction.action")
    @ResponseBody
    private Result submitMaterialProduction(@RequestBody String val){
        MProcedureIng mProcedureIng = (MProcedureIng) JSONObject.toBean(JSONObject.fromObject(val), MProcedureIng.class);
        mProcedureIng.setRegisterTime(mProcedureIng.getRegisterTime().replace("T"," "));
        List<MProcedureModuleIng> moduleIng=new ArrayList<>();
        for (int i = 0; i < mProcedureIng.getModuleIng().size(); i++) {
            moduleIng.add((MProcedureModuleIng) JSONObject.toBean(JSONObject.fromObject(mProcedureIng.getModuleIng().get(i)), MProcedureModuleIng.class));
        }
        mProcedureIng.setModuleIng(moduleIng);
        return manufactureService.submitMaterialProductionService(mProcedureIng);
    }
}
